<template>
  <div>
    <div class="udlite-container partners">
      <van-cell-group>
        <van-field v-model="uid" label="用户" placeholder="请输入用户id" />
        <van-field v-model="node_id" label="权限" placeholder="请输入权限id" />
      </van-cell-group>
      <van-button type="primary" @click="go_author">提交授权</van-button>
    </div>

    <!-- <div class="udlite-container partners">
      <table>
        用户：
        <select v-model="uid">
          <option
            v-for="(user, index) in user_list"
            :key="index"
            :value="user.id"
          >
            {{ user.username }}
          </option>
        </select>
        选择授权：
        <select v-model="node_id">
          <option
            v-for="(node, index) in node_list"
            :key="index"
            :value="node.id"
          >
            {{ node.node_name }}
          </option>
        </select>
      </table>
      <van-button type="primary" @click="go_author">提交授权</van-button>
    </div> -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      token: localStorage.getItem("token"),
      uid: "",
      node_id: "",
      user_list: [],
      node_list: [],
    };
  },
  methods: {
    go_author() {
      this.axios
        .post("http://127.0.0.1:8000/authorization/", {
          uid: this.uid,
          nodeid: this.node_id,
        })
        .then((res) => {
          this.$toast(res.data.msg);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  created() {
    this.axios
      .get("http://127.0.0.1:8000/user/", { params: { token: this.token } })
      .then((res) => {
        console.log(res);
        this.user_list = res.data.data;
      });
    this.axios.get("http://127.0.0.1:8000/node/").then((res) => {
      console.log(res);
      this.node_list = res.data.data;
    });
  },
};
</script>

<style>
</style>